import java.util.Arrays;

public class Leetcode2325 {

    public static void main(String[] args) {
        System.out.println(decodeMessage("the quick brown fox jumps over the lazy dog", "vkbs bs t suepuv"));
    }

    public static String decodeMessage(String key, String message) {
        int[] keyOffset = new int[26];
        boolean[] isHandle = new boolean[26];
        int successNumber = 0;
        char[] chars = key.toCharArray();
        for (char c : chars) {
            if (' ' == c) {
                continue;
            }

            int index = c - 'a';
            if (isHandle[index]) {
                continue;
            }

            isHandle[index] = true;
            keyOffset[c - 'a'] = successNumber + 'a';
            successNumber++;
            if (successNumber == 26) {
                break;
            }
        }

        StringBuilder res = new StringBuilder();
        char[] messageChars = message.toCharArray();
        for (char c : messageChars) {
            if (' ' == c) {
                res.append(' ');
                continue;
            }

            res.append((char) keyOffset[c - 'a']);
        }

        return res.toString();
    }
}
